package com.hjxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hjxy.dao.ClassroomDao;
import com.hjxy.pojo.Classroom;
import com.hjxy.service.ClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * @description:
 * @author: fcz
 * @createDate: 2020/9/29
 * @version: 1.0
 */@Service
public class ClassroomServiceImpl implements ClassroomService {

    private ClassroomDao classroomDao;

    @Autowired //自动装备
    public ClassroomServiceImpl(ClassroomDao classroomDao) {
        this.classroomDao = classroomDao;
    }

    @Override
    public List<Classroom> getAll() {
        return classroomDao.queryAll();
    }

  /*  @Override
    public Classroom getOneByClassroomId(Integer classroomId) {
        Classroom classroom = classroomDao.queryById(classroomId);
        System.out.println(classroom);
        return classroom;
    }

    @Override
    public Classroom getOneByClassroomname(String classroomname) {
        return classroomDao.queryByUsername(classroomname);
    }

    @Override
    public PageInfo<Classroom> getClassroomsByPage(Integer currentPage, Integer pageSize) {
        //准备拦截mybatis后续的查询
        PageHelper.startPage(currentPage, pageSize);
        List<Classroom> classroomList = classroomDao.queryAll();
        System.out.println(classroomList.size());
        //pagehelper内部计算总共有多少页
        PageInfo<Classroom> pageInfo = new PageInfo<>(classroomList);
        return pageInfo;
    }

    @Override
    public boolean addOne(Classroom classroom) {
        int result = classroomDao.insertByUser(classroom);
        //判断添加的用户的角色信息是否为空
//        if(classroom.getRoles() != null){
//            //遍历用户的角色，以循环执行user_role表的插入动作
//            for(Role role:classroom.getRoles()){
//                //构造UserRole对象
//                ClassroomRole classroomRole = new ClassroomRole();
//                classroomRole.setRoleId(role.getRoleId());
//                classroomRole.setClassroomId(classroom.getClassroomId());
//                //让userRoleDao执行插入UserRole
//                classroomRoleDao.insert(classroomRole);
//            }
//        }
        return result > 0;
    }

    @Override
    public boolean removeOne(Classroom classroom) {
        int result = classroomDao.deleteByUser(classroom);
        return result > 0;
    }

    @Override
    @Transactional //注明当前的方法事务性执行
    public boolean modifyOne(Classroom classroom) {
        int result = classroomDao.updateByUser(classroom);
        return result > 0;
    }

    @Override
    //逻辑删除一批用户
    public boolean removeSome(Set<Integer> classroomIds) {
        int result = classroomDao.deleteByIds(classroomIds);
        return result > 0;
    }

    @Override
    public Set<Classroom> getClassroomThatAddressLike(String address) {
//        这里address就是数据库user表的列名
        String column = "address";
        return classroomDao.queryByColumn(column, address);
    }

    @Override
    public Set<Classroom> getClassroomWithMultiCondition(String classroomId, int state) {
        return classroomDao.queryByMultiConditions(classroomId);
    }*/
}
